const express = require('express');
const { body, param } = require('express-validator');
const FavoriteController = require('../../controllers/FavoriteController');
const { authenticateJWT } = require('../../middleware/auth');

const router = express.Router();

// 需要认证的接口
// 视频收藏/取消收藏
router.post('/video/:videoId', authenticateJWT, [
  param('videoId').isNumeric().withMessage('视频ID必须是数字')
], FavoriteController.toggleVideoFavorite);

// 检查用户是否收藏了视频
router.get('/video/:videoId/check', authenticateJWT, [
  param('videoId').isNumeric().withMessage('视频ID必须是数字')
], FavoriteController.checkVideoFavorite);

// 批量检查视频收藏状态
router.post('/video/batch/check', authenticateJWT, [
  body('videoIds').isArray().withMessage('videoIds必须是数组').notEmpty().withMessage('videoIds不能为空'),
  body('videoIds.*').isNumeric().withMessage('视频ID必须是数字')
], FavoriteController.batchCheckVideoFavorite);

// 批量收藏视频
router.post('/video/batch', authenticateJWT, [
  body('videoIds').isArray().withMessage('videoIds必须是数组').notEmpty().withMessage('videoIds不能为空'),
  body('videoIds.*').isNumeric().withMessage('视频ID必须是数字')
], FavoriteController.batchFavoriteVideos);

// 批量取消收藏视频
router.delete('/video/batch', authenticateJWT, [
  body('videoIds').isArray().withMessage('videoIds必须是数组').notEmpty().withMessage('videoIds不能为空'),
  body('videoIds.*').isNumeric().withMessage('视频ID必须是数字')
], FavoriteController.batchUnfavoriteVideos);

// 清空用户收藏
router.delete('/user/clear', authenticateJWT, FavoriteController.clearUserFavorites);

module.exports = router;